import { warn } from 'cc';
import { _decorator, Component, Node } from 'cc';

/**
 * ui组件
 */
export class UIComp extends Component {
    /** 节点表 */
    ui: { [uiName: string]: Node } = {};

    __preload() {
        super.__preload && super.__preload();
        this.walkUI(this.node);
    }

    walkUI(uiRoot: Node) {
        if (uiRoot.name.charAt(0) == "_") {
            return;
        };
        if (this.ui[uiRoot.name] != null) {
            // warn("节点树重复", uiRoot.name);
        }
        this.ui[uiRoot.name] = uiRoot;
        uiRoot.children.forEach((c) => this.walkUI(c));
    }

    /** 注册触摸事件 */
    regTouchEvent(node: Node, callBack: Function, target: Component | Node) {
        node.on(Node.EventType.TOUCH_END, callBack, target);
    }
}


